﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
using SQLExecute;

public partial class profiles_profile_details : System.Web.UI.Page
{
    DataSet ds;
    ReportDocument rptDoc = new ReportDocument();
    public string strGraduationDegree;
    public string strWorkingExperience;
    string fullname;
    

    Profiles p = new Profiles();
    public string strEmail;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack&&!IsCallback)
        {
            if (Request.Params["id"] == null&& Session["username"] == null && Session["fullname"] == null)
           
                Response.Redirect("../login/login.aspx");
           
            else 
            {
                if (Request.Params["id"] != null)
                {
                    Get_Profile_Info();
                    Set_Profile_Info();
                    Set_Skills_Qualification();
                    Set_Working_Experience();
                    Set_Interview_Evaluation();
                    Set_Recruitement_Info();
                   // if (Session["username"] != null)
                        lUsername.Text = Session["username"].ToString();
                }
                else Response.Redirect("list_profiles.aspx");
            }//end else

        }
       
    }
    private void Get_Profile_Info()
    {
        Guid id = new Guid(Request.QueryString[0]);

        p.ID = id;

        ds = p.Get_Profile();
    }
    private void Set_Profile_Info()
    {
        lFullName.Text = ds.Tables[0].Rows[0]["fullname"].ToString().ToUpper();

        lSex.Text = ds.Tables[0].Rows[0]["sex"].ToString();
      
        if (ds.Tables[0].Rows[0]["mail"].ToString() != "")
            strEmail = "<a href=" + "mailto:" + ds.Tables[0].Rows[0]["mail"].ToString()
                        + " style=" + "color:#b80501;"
                       + ">"
                      + ds.Tables[0].Rows[0]["mail"].ToString() + "</a>";

        if (ds.Tables[0].Rows[0]["number_of_childrens"].ToString() != "")

            lMartialStatus.Text = ds.Tables[0].Rows[0]["married"].ToString() + "-" + ds.Tables[0].Rows[0]["number_of_childrens"].ToString();
        else if (ds.Tables[0].Rows[0]["married_status_others"].ToString() != "")
            lMartialStatus.Text = ds.Tables[0].Rows[0]["married"].ToString() + "-" + ds.Tables[0].Rows[0]["married_status_others"].ToString();
        else
            lMartialStatus.Text = ds.Tables[0].Rows[0]["married"].ToString();

        string s = ds.Tables[0].Rows[0]["phone"].ToString();
       

        if (ds.Tables[0].Rows[0]["phone"].ToString() != "")
            lTele.Text = Common.Split_Number_Tele(ds.Tables[0].Rows[0]["phone"].ToString());
        lHeight.Text = ds.Tables[0].Rows[0]["height"].ToString();
        lWeight.Text = ds.Tables[0].Rows[0]["weight"].ToString();

        if (ds.Tables[0].Rows[0]["birth"].ToString() != "")
        {
            //Convert.ToDateTime(ds.Tables[0].Rows[0]["availabledate"].ToString()).ToString("dd/MM/yyyy");
            lDateOfbirth.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["birth"].ToString()).ToString("dd/MM/yyyy");
            //DateTime.Parse(ds.Tables[0].Rows[0]["birth"].ToString()).ToShortDateString();
        }
        lPos.Text = ds.Tables[0].Rows[0]["pos"].ToString();

        if (ds.Tables[0].Rows[0]["expectedsalary"].ToString() != "" && ds.Tables[0].Rows[0]["expectedsalary"].ToString() != "0")
        {
            Decimal money = Decimal.Parse(ds.Tables[0].Rows[0]["expectedsalary"].ToString());

            lExpectedSalary.Text = String.Format("${0:#,###}", money);
        }
        else
        {
            lExpectedSalary.Visible = false;
            lCurrentSalary.Visible = false;
        }

        
        if (ds.Tables[0].Rows[0]["availabledate"].ToString().Length > 0)
            lAvailableDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["availabledate"].ToString()).ToString("dd/MM/yyyy");
        

        lCurrentSalary.Text = ds.Tables[0].Rows[0]["currency_salary"].ToString();
        lCurrentAddress.Text = ds.Tables[0].Rows[0]["current_address"].ToString();
        lRegisteredResidence.Text = ds.Tables[0].Rows[0]["permanent_address"].ToString();
        lIDCard.Text = ds.Tables[0].Rows[0]["id_card"].ToString();
        lRelocate.Text = ds.Tables[0].Rows[0]["relocate"].ToString();

        lAptitude.Text = ds.Tables[0].Rows[0]["aptitude"].ToString();
        lKnownFrom.Text = ds.Tables[0].Rows[0]["known_from"].ToString();
        lCarreerOjectives.Text = ds.Tables[0].Rows[0]["carreerobjectives"].ToString();
        Set_Skills_Qualification();
        Set_Working_Experience();




    }
    private void Set_Skills_Qualification()
    {
        strGraduationDegree = ds.Tables[0].Rows[0]["info_degree_date1"].ToString()
                              +": " +ds.Tables[0].Rows[0]["degree1"].ToString()
                              +", " +ds.Tables[0].Rows[0]["schoolname1"].ToString()
                              +", hệ "+ds.Tables[0].Rows[0]["trainingname1"].ToString()
                              +", "+ds.Tables[0].Rows[0]["major_name1"].ToString();
            
        if (ds.Tables[0].Rows[0]["degree2"].ToString() != ""
                                || ds.Tables[0].Rows[0]["schoolname2"].ToString() != ""
                               || ds.Tables[0].Rows[0]["major_name2"].ToString() != ""
                              || ds.Tables[0].Rows[0]["trainingname2"].ToString() != "")
        {
            strGraduationDegree += "<br />"
                                + ds.Tables[0].Rows[0]["info_degree_date2"].ToString()
                                + ": " + ds.Tables[0].Rows[0]["degree2"].ToString()
                                + ", " + ds.Tables[0].Rows[0]["schoolname2"].ToString()
                                + ", " + ds.Tables[0].Rows[0]["trainingname2"].ToString()
                                + ", " + ds.Tables[0].Rows[0]["major_name2"].ToString();
                              
                                

        }

        if (ds.Tables[0].Rows[0]["degree3"].ToString() != ""
                                || ds.Tables[0].Rows[0]["schoolname3"].ToString() != ""
                               || ds.Tables[0].Rows[0]["major_name3"].ToString() != ""
                              || ds.Tables[0].Rows[0]["trainingname3"].ToString() != "")
        {
            strGraduationDegree += "<br />" + ds.Tables[0].Rows[0]["degree3"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["schoolname3"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["major3"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["type_of_training3"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["trainingname3"].ToString();

        }
        if (ds.Tables[0].Rows[0]["degree4"].ToString() != ""
                                || ds.Tables[0].Rows[0]["schoolname4"].ToString() != ""
                               || ds.Tables[0].Rows[0]["major_name4"].ToString() != ""
                              || ds.Tables[0].Rows[0]["trainingname4"].ToString() != "")
        {
            strGraduationDegree += "<br />" + ds.Tables[0].Rows[0]["degree4"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["schoolname4"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["major4"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["type_of_training4"].ToString()
                                + "-" + ds.Tables[0].Rows[0]["trainingname4"].ToString();
        }
        lHighestDegree.Text = ds.Tables[0].Rows[0]["degree_type"].ToString();
        lEnglishLanguage.Text = ds.Tables[0].Rows[0]["english_skills"].ToString();
        lOtherLanguage.Text = ds.Tables[0].Rows[0]["other_language"].ToString();

        lComputerSkill.Text = ds.Tables[0].Rows[0]["computer_skills"].ToString();
        lOthersSkill.Text = ds.Tables[0].Rows[0]["other_skills"].ToString();


    }
    private void Set_Interview_Evaluation()
    {
        //interview 1
        ltInterview1.Text = ds.Tables[0].Rows[0]["interview1"].ToString();
        ltPos1.Text = ds.Tables[0].Rows[0]["interviewpos1"].ToString();
        ltDep1.Text = ds.Tables[0].Rows[0]["interviewdep1"].ToString();
        ltComment1.Text = ds.Tables[0].Rows[0]["comment1"].ToString();

        
        
        ltInterview2.Text = ds.Tables[0].Rows[0]["interview2"].ToString();
        ltPos2.Text = ds.Tables[0].Rows[0]["interviewpos2"].ToString();
        ltDep2.Text = ds.Tables[0].Rows[0]["interviewdep2"].ToString();
        ltComment2.Text = ds.Tables[0].Rows[0]["comment2"].ToString();
        
        ltEnglishTestResult.Text = ds.Tables[0].Rows[0]["english_result"].ToString();
        ltWord.Text = ds.Tables[0].Rows[0]["word_result"].ToString();
        ltExcel.Text = ds.Tables[0].Rows[0]["excel_result"].ToString();
        ltConclusion.Text = ds.Tables[0].Rows[0]["interview_conclusion"].ToString();
        


        ltFinalDecision.Text = ds.Tables[0].Rows[0]["final_decision"].ToString();
        ltPos3.Text = ds.Tables[0].Rows[0]["interviewpos3"].ToString();
        ltDep3.Text = ds.Tables[0].Rows[0]["interviewdep3"].ToString();
        ltComment3.Text = ds.Tables[0].Rows[0]["comment3"].ToString();



      
    }
    private void Set_Recruitement_Info()
    {

        ltRecruitmentConclusion.Text = ds.Tables[0].Rows[0]["recruitment_conclusion"].ToString();
        ltRecruitmentPositionOffer.Text = ds.Tables[0].Rows[0]["position_offer"].ToString();
        ltRecruitmentDep.Text = ds.Tables[0].Rows[0]["dept"].ToString();

        if (ds.Tables[0].Rows[0]["salary"].ToString() != "" && ds.Tables[0].Rows[0]["salary"].ToString() != "0")
        {
            Decimal money = Decimal.Parse(ds.Tables[0].Rows[0]["salary"].ToString());
            ltSalary.Text = String.Format("${0:#,###}", money);

        }
        ltRecruitmentNote.Text = ds.Tables[0].Rows[0]["note"].ToString();
        
        if (ds.Tables[0].Rows[0]["starting_date"].ToString() != "")
            ltRecruitmentStartingDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["starting_date"].ToString()).ToString("dd/MM/yyyy");
        

        if (ds.Tables[0].Rows[0]["company_id"].ToString() != "")
            lCompany.Text = ds.Tables[0].Rows[0]["company_id"].ToString();


    }
    private void Set_Working_Experience()
    {

        string s1 = string.Empty, s2 = string.Empty, s3 = string.Empty, s4 = string.Empty;
        if (ds.Tables[0].Rows[0]["pos1"].ToString() != ""
            && ds.Tables[0].Rows[0]["employer1"].ToString() != "")
            s1 = ds.Tables[0].Rows[0]["pos1"].ToString() + ", " 
               + ds.Tables[0].Rows[0]["employer1"].ToString();

        if (ds.Tables[0].Rows[0]["pos2"].ToString() != ""
            && ds.Tables[0].Rows[0]["employer2"].ToString() != "")
            s2 = ds.Tables[0].Rows[0]["pos2"].ToString() + ", "
               + ds.Tables[0].Rows[0]["employer2"].ToString();

        if (ds.Tables[0].Rows[0]["pos3"].ToString() != ""
            && ds.Tables[0].Rows[0]["employer3"].ToString() != "")
            s3 = ds.Tables[0].Rows[0]["pos3"].ToString() + ", "
               + ds.Tables[0].Rows[0]["employer3"].ToString();

        if (s2.Length > 0)
            strWorkingExperience = s1 + "<br />" + s2;
        if (s3.Length > 0)
            strWorkingExperience += "<br />" + s3;
     
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("list_profiles.aspx");
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {

        Response.Redirect("~/profiles/print_profile.aspx?id=" + Request.QueryString["id"].ToString());
       

    }
    protected void LoadImage(DataRow r, string strImageField, string strPath)
    {
        try
        {
            FileStream f = new FileStream(strPath, FileMode.Open, FileAccess.Read);
            byte[] img = new byte[f.Length];
            f.Read(img, 0, Convert.ToInt32(f.Length));
            f.Close();
            r[strImageField] = img;
        }

        catch (Exception ex)
        {
            Response.Write("<font color=red>" + ex.Message + "</font>");
        }

    }
    protected void btnExportPDF_Click(object sender, EventArgs e)
    {
       
        if (Request.Params["id"] != null)
        {

            Utility ex = new Utility();

            string strID = Request.QueryString["id"].ToString();
            Guid id = new Guid(strID);
            ex.Export2PDF2(id);            
            ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('../export/profile.pdf');popup.focus();", true);
        }

    }
    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
       
        Session.Clear();
        Response.Redirect("../login/login.aspx");
    }

    //window.open('../export/'" +"profile_Đỗ Hồ Hạnh Trinh.xls" + "');popup.focus();", true);
    protected void btnExportExcel_Click(object sender, EventArgs e)
    {
        string filename;
        if (Request.Params["id"] != null)
        {
            Utility ex = new Utility();
            string strID = Request.QueryString["id"].ToString();
            Guid id = new Guid(strID);
          
            filename ="profile_" +ex.Export2Excel(id)+".xls";

            string path = "var popup=window.open('../export/" +filename+ "');popup.focus();";
            ClientScript.RegisterStartupScript(this.Page.GetType(),"popupOpener",path , true);
            
           // ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('../export/profile_Đỗ Hồ Hạnh Trinh.xls');popup.focus();", true);
        }
    }
}
